<?php
// 加载通用文件
require_once __DIR__ . '/../../common/autoload.php';

// 检查是否已安装
if (!file_exists(__DIR__ . '/../../.installed') && basename($_SERVER['PHP_SELF']) !== 'install.php') {
    header('Location: /install.php');
    exit;
}

// 检查登录状态（除登录页面外）
if (basename($_SERVER['PHP_SELF']) !== 'login.php') {
    check_login();
}

// 获取当前用户
$current_user = current_user();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>餐饮收银系统 - POS终端</title>
    <!-- CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
    <link rel="stylesheet" href="/assets/css/style.css">
    <!-- 加载POS终端特定样式 -->
    <link rel="stylesheet" href="/POS/assets/css/pos.css">
    <!-- 添加SweetAlert2库 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18/dist/sweetalert2.min.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18/dist/sweetalert2.all.min.js"></script>
    <!-- jQuery和Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
    <div class="admin-layout">
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="sidebar-header">
                <div class="sidebar-logo">POS 收银系统</div>
            </div>
            <div class="sidebar-menu">
                <a href="/POS/index.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'index.php' ? 'active' : ''; ?>">
                    <i class="fas fa-home"></i> <span>首页</span>
                </a>
                <a href="/POS/products.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'products.php' ? 'active' : ''; ?>">
                    <i class="fas fa-utensils"></i> <span>点餐</span>
                </a>
                <a href="/POS/orders.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'orders.php' ? 'active' : ''; ?>">
                    <i class="fas fa-clipboard-list"></i> <span>订单管理</span>
                </a>
                <a href="/POS/members.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'members.php' ? 'active' : ''; ?>">
                    <i class="fas fa-users"></i> <span>会员管理</span>
                </a>
                <?php if ($current_user && $current_user['role'] === 'admin'): ?>
                <a href="/POS/products_manage.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'products_manage.php' ? 'active' : ''; ?>">
                    <i class="fas fa-cubes"></i> <span>商品管理</span>
                </a>
                <a href="/POS/categories.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'categories.php' ? 'active' : ''; ?>">
                    <i class="fas fa-tags"></i> <span>分类管理</span>
                </a>
                <a href="/POS/reports.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'reports.php' ? 'active' : ''; ?>">
                    <i class="fas fa-chart-bar"></i> <span>销售报表</span>
                </a>
                <a href="/POS/settings.php" class="sidebar-menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'settings.php' ? 'active' : ''; ?>">
                    <i class="fas fa-cog"></i> <span>系统设置</span>
                </a>
                <?php endif; ?>
                <a href="/POS/logout.php" class="sidebar-menu-item">
                    <i class="fas fa-sign-out-alt"></i> <span>退出登录</span>
                </a>
            </div>
        </div>
        
        <!-- 主内容区 -->
        <div class="main-content">
            <!-- 头部导航 -->
            <div class="header">
                <button class="mobile-nav-toggle d-md-none">
                    <i class="fas fa-bars"></i>
                </button>
                <div class="header-title">
                    <?php 
                    $page_title = '收银系统';
                    switch (basename($_SERVER['PHP_SELF'])) {
                        case 'index.php': $page_title = '收银系统 - 首页'; break;
                        case 'products.php': $page_title = '点餐'; break;
                        case 'orders.php': $page_title = '订单管理'; break;
                        case 'members.php': $page_title = '会员管理'; break;
                        case 'products_manage.php': $page_title = '商品管理'; break;
                        case 'categories.php': $page_title = '分类管理'; break;
                        case 'reports.php': $page_title = '销售报表'; break;
                        case 'settings.php': $page_title = '系统设置'; break;
                    }
                    echo $page_title;
                    ?>
                </div>
                <div class="user-info">
                    <a href="/POS/logout.php" class="btn btn-sm btn-secondary">
                        <i class="fas fa-sign-out-alt"></i> 退出
                    </a>
                </div>
            </div>
            
            <!-- 提示消息容器 -->
            <div id="alert-container" class="mt-3"></div>
            
            <!-- 主要内容 -->
            <div class="page-content">
        </div>
    </div>
</body>
</html> 